package com.ruoyi.web.controller.comprehensive;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.pengjie.SnowflakeIdUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.comprehensive.domain.FirePrevention;
import com.ruoyi.comprehensive.dto.FirePreventionDto;
import com.ruoyi.comprehensive.service.IFirePreventionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 防火管理Controller
 *
 * @author hcc
 * @date 2023-12-16
 */
@RestController
@RequestMapping("/comprehensive/fire")
public class FirePreventionController extends BaseController
{
    @Autowired
    private IFirePreventionService firePreventionService;

    /**
     * 查询防火管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:fire:list')")
    @GetMapping("/list")
    public TableDataInfo list(FirePrevention firePrevention)
    {
        startPage();
        List<FirePrevention> list = firePreventionService.selectFirePreventionList(firePrevention);
        return getDataTable(list);
    }

    /**
     * 导出防火管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:fire:export')")
    @Log(title = "防火管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FirePrevention firePrevention)
    {
        List<FirePrevention> list = firePreventionService.selectFirePreventionList(firePrevention);
        ExcelUtil<FirePrevention> util = new ExcelUtil<FirePrevention>(FirePrevention.class);
        util.exportExcel(response, list, "防火管理数据");
    }

    /**
     * 获取防火管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:fire:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(firePreventionService.selectFirePreventionById(id));
    }

    /**
     * 新增防火管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:fire:add')")
    @Log(title = "防火管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FirePrevention firePrevention)
    {
        firePrevention.setId(String.valueOf(new SnowflakeIdUtils(5,8).nextId()));
        return toAjax(firePreventionService.insertFirePrevention(firePrevention));
    }

    /**
     * 修改防火管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:fire:edit')")
    @Log(title = "防火管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FirePrevention firePrevention)
    {
        return toAjax(firePreventionService.updateFirePrevention(firePrevention));
    }

    /**
     * 删除防火管理
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:fire:remove')")
    @Log(title = "防火管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(firePreventionService.deleteFirePreventionByIds(ids));
    }
    /**
     * 查询防火管理列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:fire:list')")
    @GetMapping("/getList")
    public TableDataInfo getList(FirePrevention firePrevention) {
        startPage();
        List<FirePreventionDto> list = firePreventionService.getFirePreventionList(firePrevention);
        return getDataTable(list);
    }
    /**
     * 获取防火管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:fire:query')")
    @GetMapping("/getFirePreventionById/{id}")
    public AjaxResult getFirePreventionById(@PathVariable("id") String id) {
        FirePreventionDto firePreventionDto = firePreventionService.getFirePreventionById(id);
        return success(firePreventionDto);
    }
}
